// https://iai.sh.cn/problem/442
#include <bits/stdc++.h>
using namespace std;
int a[300001];
int sum[300001];
typedef long long LL;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    sum[i] = sum[i - 1] + a[i];
  }
  LL leftM = 0;
  LL rightM = 0;
  for (int i = 2; i <= n; i++) {
    rightM += a[i] * (i - 1);
  }

  LL king = 0x3f3f3f3f;
  for (int i = 2; i <= n - 1; i++) {
    leftM += sum[i - 1];
    rightM -= sum[n] - sum[i - 1];
    king = min(king, abs(leftM - rightM));
  }
  cout << king;
  return 0;
}